﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;
using Microsoft.Reporting.WinForms;

namespace QLKH.View.Hoadon
{
    public partial class ViewHoaDonCaNhan : Form
    {
        public ViewHoaDonCaNhan()
        {
            InitializeComponent();
            this.Height = Screen.PrimaryScreen.WorkingArea.Height; //ConfigForm.height;
        }

        private void ViewHoaDonCaNhan_Load(object sender, EventArgs e)
        {
            this.reportViewerHDCaNhan.RefreshReport();

            clKhachhang clkh = new clKhachhang();
            AutoCompleteStringCollection dskh = new AutoCompleteStringCollection();

            DataTable dtds = clkh.getautocomplete(0, 0);
            if (dtds != null && dtds.Rows.Count > 0)
            {
                foreach (DataRow row in dtds.Rows)
                {
                    dskh.Add(row["maCu"].ToString());
                }
            }

            txtMaKH.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtMaKH.AutoCompleteSource = AutoCompleteSource.CustomSource;
            txtMaKH.AutoCompleteCustomSource = dskh;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string thangin = dateThangin.Value.ToString("MM/dd/yyyy");
            string maKh = txtMaKH.Text.Trim();

            clHoadon clhd = new clHoadon();
            DataTable dthd = clhd.Incanhan(thangin, maKh);
            ReportDataSource rphd = new ReportDataSource();
            rphd.Name = "DataSet1";
            rphd.Value = dthd;

            this.reportViewerHDCaNhan.Reset();
            this.reportViewerHDCaNhan.LocalReport.ReportEmbeddedResource = "QLKH.View.Hoadon.SubHDCaNhan.rdlc";
            this.reportViewerHDCaNhan.LocalReport.DataSources.Clear();
            this.reportViewerHDCaNhan.LocalReport.DataSources.Add(rphd);

            string ngayphathanh = dateNgayIn.Value.ToString("dd/MM/yyyy");

            IList<ReportParameter> param = new List<ReportParameter>();
            param.Add(new ReportParameter("NgayIn", ngayphathanh));
            reportViewerHDCaNhan.LocalReport.SetParameters(param);

            this.reportViewerHDCaNhan.RefreshReport();

            this.reportViewerHDCaNhan.RefreshReport();
            this.reportViewerHDCaNhan.SetDisplayMode(DisplayMode.PrintLayout);
            this.reportViewerHDCaNhan.ZoomMode = ZoomMode.Percent;
            this.reportViewerHDCaNhan.ZoomPercent = 100;

        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
